<template>
	<div>
		<Card class="content-card">
			<Tabs :animated="false">
				<ButtonGroup slot="extra">
					<Button type="primary" size="small" icon="md-refresh" @click="refreshData"></Button>
				</ButtonGroup>
				<TabPane label="新车退货列表" name="return">
					<div style="margin-bottom:10px;">
						<span>状态</span>
						<Select v-model="params.type" style="width:200px;margin-left: 10px;">
							<Option value="0">待审核</Option>
							<Option value="1">待发货</Option>
							<Option value="2">未通过</Option>
							<Option value="3">待收货</Option>
							<Option value="4">待退款</Option>
							<Option value="5">待确认</Option>
							<Option value="6">已完成</Option>
							<Option value="7">已取消</Option>
						</Select>
						<span>主机厂</span>
						<Select v-model="params.factoryId" style="width:200px;margin-left: 10px;">
							<Option :value="item.factoryId" v-for="(item,index) in factoryList" :key="index">
							    {{item.factoryName}}
							</Option>
						</Select>
						<Button @click="refreshData" type="primary">查询</Button>
					</div>

					<table-view ref="tableView" :tableCol='tableCol' :params='params' :requestUrl='requestUrl'></table-view>
				</TabPane>
			</Tabs>
		</Card>
		<!--详情-->
		<newReturnDetail ref="newReturnDetail" :type='modalType' @table='operationDone'></newReturnDetail>
	</div>
</template>

<script>
	import tableView from '../../components/table'
	import {
		formatDate
	} from '../utils/time.js'
	import newReturnDetail from './newReturnDetail'
	export default {
		components: {
			tableView,
			newReturnDetail
		},
		data() {
			return {
				factoryList:[],
				requestUrl: '/return/new/list',
				returnStatusList: {
					0: '待审核',
					1: '待发货',
					2: '未通过',
					3: '待收货',
					4: '待退款',
					5: '待确认',
					6: '已完成',
					7: '已取消'
				},
				tableCol: [{
						title: '序号',
						type: 'index',
						width: 80,
						align: 'center'
					},
					{
						title: '单号',
						key: 'orderNum',
						minWidth: 120
					},
                    {
                        title: '车辆信息',
                        minWidth: 120,
                        render: (h, params) => {
                        var arr = params.row.returnCarList;
						return h('div', arr.map(function (item,index) {
							return h('div',{
								style: {
									marginRight: '5px'
								}
							}, item.carName + ' * ' + item.num)
						}))
					}
					},
					{
						title: '应退金额',
						minWidth: 100,
						align: 'center',
						render: (h, params) => {
							return h('div', [

								h('div', params.row.backMoney + "万元"),
							])
						}
					},
					{
						title: '退款原因',
						key: 'refundReason',
						minWidth: 100,
						align: 'center'
					},
					{
						title: '联系电话',
						key: 'userTel',
						minWidth: 100,
						align: 'center'
					}, {
						title: '订单状态',
						minWidth: 100,
						align: 'center',
						render: (h, params) => {
							return h('div', this.returnStatusList[params.row.returnType])
						}
					},
					{
						title: '日期',
						key: 'createTime',
						minWidth: 100,
						align: 'center',
						render: (h, params) => {
							return h('div', formatDate(new Date(params.row.createTime), 'yyyy-MM-dd hh:mm'))
						}
					},
					{
						title: '操作',
						minWidth: 200,
						key: 'action',
						render: (h, params) => {

							return h('div', [
								h('Button', {
									props: {
										type: 'error',
										size: 'small'
									},
									style: {
										marginLeft: '10px'
									},
									on: {
										click: () => {
											this.$Modal.confirm({
												title: '删除？',
												content: '确定要删除吗？删除不可恢复',
												onOk: () => {
													this.$http.post('/return/new/delete', {
														id: params.row.orderId
													}).then(res => {
														if (res.status == 200) {
															this.$refs['tableView'].getData()
															this.$Notice.warning({
																title: '删除成功'

															});
														}
													})
												}
											})
										}
									}
								}, '删除'),
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginLeft: '10px'
									},
									on: {
										click: () => {

											this.$refs['newReturnDetail'].show(params)
										}
									}
								}, '查看详情')
							])


						}
					}
				],
				params: {
					pageNo: 1,
					pageSize: 10,
					type: '',
					factoryId:''
				},
				modalType: ''
			}
		},
		mounted() {
			this.queryFactoryList();
		},
		methods: {
			refreshData() {
				this.$refs['tableView'].getData()
			},
			operationDone() {
				this.$refs['tableView'].getData()
			},
			getNowTime() {
				var date = new Date();
				var seperator1 = "-";
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = year + seperator1 + month + seperator1 + strDate;
				return currentdate;
			},
			queryFactoryList(){
				this.$http.post('/factory/list', {
				    pageNo: '1',
				    pageSize: '100000'
				}).then(res => {
				    if (res.status == 200) {
						if(res.data.code==200){
							this.factoryList = res.data.data.rows;
						}
				        
				    }
				});
			}
		}
	}
</script>

<style>
</style>
